/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.seari.ibpPanleMidware.service.impl;

import com.seari.ibpPanleMidware.bean.StationConfig;
import com.seari.ibpPanleMidware.mapper.StationConfigMapper;
import com.seari.ibpPanleMidware.service.StationConfigService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

/**
 *
 * @author Rainbow
 */
@Service("StationConfigService")
public class StationConfigServiceImpl implements StationConfigService
{
    @Autowired
    private StationConfigMapper stationConfigMapper;
    
    @Override
    public List<StationConfig> getStationConfig()
    {
        return stationConfigMapper.getStationConfig();
    }

    @Override
    public List<StationConfig> getStationFanConfig()
    {
        return stationConfigMapper.getStationFanConfig();
    }

    @Override
    public Map<String, String> getDataGroupIPMap()
    {
        List<Map<String,String>> dataGroupIPMapList = stationConfigMapper.getDataGroupIPMap();
        Map<String,String> dataGroupIPMap = new HashMap<>();
        if(!CollectionUtils.isEmpty(dataGroupIPMapList))
        {
            for (Map<String, String> map : dataGroupIPMapList)
            {
                String key = "";
                String value = "";
                for (Map.Entry<String, String> entry : map.entrySet())
                {
                    if("data_group".equals(entry.getKey()))
                    {
                        key = entry.getValue();
                    }else if("data_ip_list".equals(entry.getKey()))
                    {
                        value = entry.getValue();
                    }
                }
                dataGroupIPMap.put(key, value);
            }
        }
        return dataGroupIPMap;
    }
    
}
